package com.example.batchprocessing.step;

import com.example.batchprocessing.Person;
import java.util.Random;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.NonTransientResourceException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ReaderTest implements ItemReader {

  @Override
  public Object read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException {
    Person person = new Person("test", new Random().nextInt() + "");
    int n = new Random().nextInt(100);
    log.info("测试 read:{} ,n:{}", person, n);
    if (n > 60) {
      return null;
    }
//    Thread.sleep(5000);
    return person;
  }
}
